package com.itheima.dao;

import com.itheima.pojo.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface MemberDao {

    @Select("select * from t_member")
    public List<Member> getAllMember();

    @Select("select * from t_member where fileNumber like CONCAT('%',#{queryString},'%') or name like CONCAT('%',#{queryString},'%') or phoneNumber like CONCAT('%',#{queryString},'%')")
    public List<Member> getByQueryString(String queryString);

    @Insert("insert into t_member (name,phoneNumber,sex,birthday,health_manager,idCard,fileNumber,remark,regTime) " +
            "   values(#{name},#{phoneNumber},#{sex},#{birthday},#{health_manager},#{idCard},#{fileNumber},#{remark},#{regTime})")
    void insertMember(Member member);

    @Select("select * from t_member where id=#{id}")
    Member findById(Integer id);

    @Update("update t_member set name=#{name},phoneNumber=#{phoneNumber},sex=#{sex},birthday=#{birthday},health_manager=#{health_manager},idCard=#{idCard},fileNumber=#{fileNumber},remark=#{remark},regTime=#{regTime} where id=#{id}")
    void updateMember(Member member);

    @Delete("delete from t_member where id=#{id}")
    void deleteMember(Integer id);

    // 根据 Member 的 id  查询 套餐信息
    @Select("select * from t_setmeal where id in (select setmeal_id from t_order where member_id=#{memberId})")
    List<Setmeal> findByMemberId(Integer memberId);
    @Select("select * from t_checkgroup where id in(select checkgroup_id from t_setmeal_checkgroup where setmeal_id=#{setmaelId})")
    List<CheckGroup> findByCheckGroup(Integer setmaelId);

    @Select("select * from t_checkitem where id in (select checkitem_id from t_checkgroup_checkitem where checkgroup_id=#{checkGroupId})")
    List<CheckItem> findByCheckItem(Integer checkGroupId);

    @Select("select * from t_member")
    List<Member> findAll();
}
